/**
 * Copyright (C) 2017 - 2020 https://github.com/joewee
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bifrost.workflow.state;

import java.util.Stack;

/**
 * @author joewee
 * @version 1.0.0
 * @Date 2017/11/14 19:05
 */
public class RollbackStateLocal {
    private static final ThreadLocal<Stack> THREAD_LOCAL = ThreadLocalManager.createThreadLocal(Stack.class, true);

    public static RollbackStateLocal getRollbackStateLocal() {
        return (RollbackStateLocal) THREAD_LOCAL.get().peek();
    }

    public static void setRollbackStateLocal(RollbackStateLocal rollbackStateLocal) {
        Stack localState = THREAD_LOCAL.get();
        localState.push(rollbackStateLocal);
    }

    public static void clearRollbackStateLocal() {
        Stack localState = THREAD_LOCAL.get();
        localState.pop();
    }

    private String threadId;
    private String workflowId;

    public String getThreadId() {
        return threadId;
    }

    public void setThreadId(String threadId) {
        this.threadId = threadId;
    }

    public String getWorkflowId() {
        return workflowId;
    }

    public void setWorkflowId(String workflowId) {
        this.workflowId = workflowId;
    }
}
